package com.cjj.controller;

import com.cjj.common.convention.result.Result;
import com.cjj.common.convention.result.Results;
import com.cjj.dto.req.CommentCreateReqDTO;
import com.cjj.dto.resp.CommentVO;
import com.cjj.service.PostCommentService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/forum/comments")
@RequiredArgsConstructor
public class PostCommentController {
    

    private final PostCommentService postCommentService;
    
    /**
     * 创建评论
     */
    @PostMapping("/create")
    public Result<Void> createComment(@RequestBody CommentCreateReqDTO request) {
        postCommentService.createComment(request);
        return Results.success();
    }
    
    /**
     * 获取帖子评论列表
     */
    @GetMapping("/post/{postId}")
    public Result<List<CommentVO>> getPostComments(@PathVariable Long postId,
                                                   @RequestParam Long userId) {
        List<CommentVO> comments = postCommentService.getPostComments(postId, userId);
        return Results.success(comments);
    }
    
    /**
     * 删除评论
     */
    @DeleteMapping("/{commentId}")
    public Result<Void> deleteComment(@PathVariable Long commentId,@RequestParam Long userId) {
        postCommentService.deleteComment(commentId, userId);
        return Results.success();
    }

}